It shows the relationship between horsepower, weight, and miles per gallon in the mtcars dataset. Cylinder count is represented by color and displacement by size.
# 3D Scatter plot with mtcars
plot_ly(
data = mtcars,
x = ~hp, # Horsepower
y = ~wt, # Weight
z = ~mpg, # Miles per gallon
color = ~factor(cyl), # Cylinder count
size = ~disp, # Displacement for marker size
colors = c('red','green','blue'),
type = 'scatter3d',
mode = 'markers',
marker = list(symbol = 'circle', sizemode = 'diameter', opacity = 0.8)
) %>%
layout(
scene = list(
xaxis = list(title = "Horsepower (hp)"),
yaxis = list(title = "Weight (1000 lbs)"),
zaxis = list(title = "Miles per Gallon (mpg)")
),
title = "3D Scatter Plot of mtcars"
)
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.